//
//  ActicleMainViewController.m
//  MyProject
//
//  Created by dllo on 15/10/28.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ActicleMainViewController.h"
#import "HandleData.h"
#import <UIImageView+WebCache.h>
#import "LBCollectionViewCell.h"
#import "LBTableViewCell.h"
#import "LB.h"
#import "Artical.h"
#import "ArticalVideoTableViewCell.h"
#import "ArticleCommonFEIRQTableViewCell.h"
#import "ArticleCommonTableViewCell.h"
#import "ArticlePicTableViewCell.h"
#import "AticleSpecial.h"
#import "AticleSpacialTableViewCell.h"
#import "ActiclePhotoTableViewCell.h"
#import "ArticleSecoondViewController.h"
#import <MJRefresh.h>
#import "MONOViewController.h"
#import "MBProgressHUD.h"
#import "BaseViewController.h"
#define WIDTH ([UIScreen mainScreen].bounds.size.width/375)
#define HEIGH ([UIScreen mainScreen].bounds.size.height/667)
@interface ActicleMainViewController ()<UITableViewDataSource,UITableViewDelegate,PicTableViewCellDelegete,MBProgressHUDDelegate>
@property (nonatomic,strong) NSMutableArray *titleArr;
@property (nonatomic,strong) NSMutableArray *rawArr;
@property (nonatomic,strong) NSMutableArray *avatar_largeArr;
@property (nonatomic,strong) NSMutableArray *screen_nameArr;
@property (nonatomic,strong) NSMutableArray *descArr;
@property (nonatomic,strong) NSMutableArray *useidArr;
@property (nonatomic,strong) NSMutableArray *item_urlArr;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *uesTableArr;
@property (nonatomic,strong) NSMutableArray *type_nameArr;
@property (nonatomic,strong) NSMutableDictionary *useDic;
@property (nonatomic,strong) NSMutableArray *specialArr;
@property (nonatomic,strong) NSMutableDictionary *specialDic;
@property (nonatomic,strong) NSString *nextTime;
@property (nonatomic,strong) UIView *nightView;

@end

@implementation ActicleMainViewController
- (void)viewWillAppear:(BOOL)animated
{
    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"isWhite"]) {
        self.tableView.backgroundColor = [UIColor grayColor];
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
        
        [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    }
    else{
        self.tableView.backgroundColor = [UIColor whiteColor];
        self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
        self.navigationController.navigationBar.barTintColor = [UIColor redColor];
        
        [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    }
    [self.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"isWhite"]) {
//        
//                self.view.backgroundColor = [UIColor blackColor];
//            }
//            else{
//                self.view.backgroundColor = [UIColor whiteColor];
//            }

//    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
//    [center addObserver:self selector:@selector(recevive:) name:@"cahnge" object:nil];
    
    
  //  self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhuidingbu@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(returnHead)];
    
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    //去掉下拉条
//    self.tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:self.tableView];
    [self.tableView registerClass:[LBTableViewCell class] forCellReuseIdentifier:@"image"];
    [self.tableView registerClass:[ArticlePicTableViewCell class] forCellReuseIdentifier:@"pic"];
    [self.tableView registerClass:[ArticalVideoTableViewCell class] forCellReuseIdentifier:@"Video"];
    [self.tableView registerClass:[ArticleCommonFEIRQTableViewCell class] forCellReuseIdentifier:@"common"];
    [self.tableView registerClass:[ArticleCommonTableViewCell class] forCellReuseIdentifier:@"sign"];
    [self.tableView registerClass:[AticleSpacialTableViewCell class] forCellReuseIdentifier:@"special"];
    [self.tableView registerClass:[ActiclePhotoTableViewCell class] forCellReuseIdentifier:@"photo"];
    
    [self LBhandleData];
    [self initArray];
     [self DetailhandleData];
    //     上拉加载
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self loadDataHandler];
        [_tableView.footer endRefreshing];
    }];
    
    self.tableView.footer = footer;

}
- (void)returnHead
{
    [self.tableView setContentOffset:CGPointMake(0, -64) animated:YES];

}
- (void)initArray
{
    self.titleArr = [NSMutableArray array];
    self.rawArr = [NSMutableArray array];
    self.avatar_largeArr = [NSMutableArray array];
    self.screen_nameArr = [NSMutableArray array];
    self.descArr = [NSMutableArray array];
    self.useidArr = [NSMutableArray array];
    self.item_urlArr = [NSMutableArray array];
    
}
- (void)LBhandleData
{
//    [[UIButton appearance] setTitleColor:<#(nullable UIColor *)#> forState:<#(UIControlState)#>]
    MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.mode = MBProgressHUDModeIndeterminate;
    HUD.labelText = @"loading";
    HUD.detailsLabelText = @"网络加载中,请稍等";
//    HUD.dimBackground = YES; 
    [HandleData handleDataWithUrl:@"http://mmmono.com/api/v2/banner/home_stickie/" completion:^(id data) {
        if (data) {
           [HUD hide:YES afterDelay:0];
        }
        NSMutableDictionary *allDic = data;
        NSMutableArray *allArr = [allDic objectForKey:@"data"];
        for (NSMutableDictionary *dic in allArr) {
            NSMutableDictionary *dict = [dic objectForKey:@"item"];
            LB *lb = [[LB alloc]init];
            [lb setValuesForKeysWithDictionary:dict];
            [_titleArr addObject:lb.title];
            [_rawArr addObject:[[dict objectForKey:@"thumb"] objectForKey:@"raw"]];
            [_avatar_largeArr addObject:[[dict objectForKey:@"cp"] objectForKey:@"avatar_large"]];
            [_screen_nameArr addObject:[[dict objectForKey:@"cp"] objectForKey:@"screen_name"]];
            [_descArr addObject:[[dict objectForKey:@"content"] objectForKey:@"desc"]];
            [_useidArr addObject:lb.useid];
            [_item_urlArr addObject:lb.item_url];
            
        }
        
//        NSLog(@"qqqqqqq%@",_titleArr);
//        NSLog(@"wwwwwww%@",_rawArr);
//        NSLog(@"eeeeee%@",_avatar_largeArr);
//        NSLog(@"rrrrrrr%@",_screen_nameArr);
//        NSLog(@"tttttt%@",_descArr);
//        NSLog(@"yyyyyy%@",_useidArr);
//        NSLog(@"uuuuuuuu%@",_item_urlArr);
        
        [self.tableView reloadData];
         [self.tableView.header endRefreshing];
        
    }];
    
    
}
- (void)DetailhandleData
{
    self.uesTableArr = [NSMutableArray array];
    self.type_nameArr = [NSMutableArray array];
    self.specialArr = [NSMutableArray array];
    self.specialDic = [NSMutableDictionary dictionary];
    [HandleData handleDataWithUrl:@"http://mmmono.com/api/v2/waterfall/" completion:^(id data) {
        NSMutableDictionary *allDic = data;
        //        NSLog(@"WWWWWWW%@",allDic);
        NSDictionary *nextDic = [data objectForKey:@"next"];
        _nextTime = [nextDic objectForKey:@"w_datetime"] ;
        NSMutableArray *arr = [allDic objectForKey:@"waterfall"];
        for (NSMutableDictionary *dic in arr) {
//            NSLog(@"++++++%@",dic);
            if ( [dic objectForKey:@"item"]) {
                self.useDic = [dic objectForKey:@"item"];
                            Artical *artical = [[Artical alloc]init];
                            [artical setValuesForKeysWithDictionary:_useDic];
                                [self.uesTableArr addObject:artical];
            }else{
//            self.useDic = [dic objectForKey:@"item"];
////            NSLog(@"+++%@",_useDic);
//
//            Artical *artical = [[Artical alloc]init];
//            [artical setValuesForKeysWithDictionary:_useDic];
//                [self.uesTableArr addObject:artical];
//            if ([dic objectForKey:@"special"]) {
                self.specialDic = [dic objectForKey:@"special"];
                AticleSpecial *special = [AticleSpecial alloc];
                [special setValuesForKeysWithDictionary:self.specialDic];
                [_uesTableArr addObject:special];
                NSLog(@"~~~~~~~%@",_uesTableArr);
//                }
            
            }
//            NSLog(@"%@",[artical.thumb objectForKey:@"raw"]);
        
        }
        Artical *articaltemp = [self.uesTableArr firstObject];
        NSLog(@"!!!!!!!!!!%@", [articaltemp.thumb objectForKey:@"raw"]);
        
        AticleSpecial *spe = [self.uesTableArr firstObject];
        NSLog(@"_______%@",[spe.thumb objectForKey:@"raw"]);
        
        [self.tableView reloadData];
         [self.tableView.header endRefreshing];
     
        
    }];
    //      下拉刷新
    
  self.tableView.header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
      [HandleData handleDataWithUrl:@"http://mmmono.com/api/v2/waterfall/" completion:^(id data) {
          
          self.uesTableArr = [NSMutableArray array];
          self.type_nameArr = [NSMutableArray array];
          self.specialArr = [NSMutableArray array];
          
          NSMutableDictionary *allDic = data;
          //        NSLog(@"WWWWWWW%@",allDic);
          NSDictionary *nextDic = [data objectForKey:@"next"];
          _nextTime = [nextDic objectForKey:@"w_datetime"] ;
          NSMutableArray *arr = [allDic objectForKey:@"waterfall"];
          for (NSMutableDictionary *dic in arr) {
              //            NSLog(@"++++++%@",dic);
              if ( [dic objectForKey:@"item"]) {
                  self.useDic = [dic objectForKey:@"item"];
                  Artical *artical = [[Artical alloc]init];
                  [artical setValuesForKeysWithDictionary:_useDic];
                  [self.uesTableArr addObject:artical];
              }else{
                
                  self.specialDic = [dic objectForKey:@"special"];
                  AticleSpecial *special = [AticleSpecial alloc];
                  [special setValuesForKeysWithDictionary:self.specialDic];
                  [_uesTableArr addObject:special];
                  NSLog(@"~~~~~~~%@",_uesTableArr);
                  //                }
                  
              }
              //            NSLog(@"%@",[artical.thumb objectForKey:@"raw"]);
              
          }
          Artical *articaltemp = [self.uesTableArr firstObject];
          NSLog(@"!!!!!!!!!!%@", [articaltemp.thumb objectForKey:@"raw"]);
          
          AticleSpecial *spe = [self.uesTableArr firstObject];
          NSLog(@"_______%@",[spe.thumb objectForKey:@"raw"]);
          
          [self.tableView reloadData];
          [self.tableView.header endRefreshing];

  }];
      
       // [self DetailhandleData];
        //        [self LBhandleData];
    }];
    
//    self.tableView.header = header;
//    
    //     马上进入刷新
   // [self.tableView.header beginRefreshing];
    
      //

//    NSLog(@"++++++++%@",_uesTableArr);
//    NSLog(@"&&&&&&%@",_specialArr);
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 300 * HEIGH;
    }else{
        return  380 * HEIGH;
    }
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if ([[self.uesTableArr objectAtIndex:indexPath.row] isKindOfClass:[Artical class]]) {
        Artical *art = [self.uesTableArr objectAtIndex:indexPath.row];
        ArticleSecoondViewController *second = [[ArticleSecoondViewController alloc]init];
        second.use = art.item_url;
        NSLog(@"SDSD%@",second.use);
        NSLog(@"ftftf%@",art.item_url);
        [self.navigationController pushViewController:second animated:YES];
        
        
    }
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else{
//        NSLog(@"%ld", _uesTableArr.count);
        return self.uesTableArr.count ;
       
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        LBTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"image"];
        cell.bgpicArray = [NSMutableArray array];
        cell.bgpicArray = self.rawArr;
        
        cell.idArray = [NSMutableArray array];
        cell.idArray = self.useidArr;
        
        cell.item_urlArray = [NSMutableArray array];
        cell.item_urlArray = self.item_urlArr;
        
        cell.titleArray = [NSMutableArray array];
        cell.titleArray = self.titleArr;
        
        cell.commenImageArray = [NSMutableArray array];
        cell.commenImageArray = self.avatar_largeArr;
        
        cell.commenTitleArray = [NSMutableArray array];
        cell.commenTitleArray = self.screen_nameArr;
        
        cell.describArray = [NSMutableArray array];
        cell.describArray = self.descArr;
        
        cell.delegate = self;
        
        
        [cell.collectionView reloadData];
        
        return cell;
    }else {
        
        
//         [self.uesTableArr objectAtIndex:indexPath.row];
//        [self.specialArr objectAtIndex:indexPath.row];
        //有两种类或者多种类的时候需要判断取哪种类
        AticleSpecial *sp = [self.uesTableArr objectAtIndex:indexPath.row];
        if ([sp isKindOfClass:[AticleSpecial class]]) {
            AticleSpacialTableViewCell *specialCell = [self.tableView dequeueReusableCellWithIdentifier:@"special"];
//            AticleSpecial *special = [self.uesTableArr objectAtIndex:indexPath.row];
                        [specialCell.bgImage sd_setImageWithURL:[NSURL URLWithString:[[self.specialDic objectForKey:@"thumb"] objectForKey:@"raw"]]placeholderImage:[UIImage imageNamed:@"lovebeijing.png"]];
            specialCell.backgroundColor = [UIColor clearColor];
            if (![[NSUserDefaults standardUserDefaults]boolForKey:@"isWhite"]) {
                
            }else{
                
            }
            
            return specialCell;
            
        }else{
//        AticleSpecial *special = [self.uesTableArr objectAtIndex:indexPath.row];
        Artical *artical =  [self.uesTableArr objectAtIndex:indexPath.row];
        
        if ([artical.type_name isEqualToString:@"日签"]) {
            ArticleCommonTableViewCell *rqCell = [self.tableView dequeueReusableCellWithIdentifier:@"sign"];
            [rqCell.bgImage sd_setImageWithURL:[NSURL URLWithString:[artical.thumb objectForKey:@"raw"]]placeholderImage:[UIImage imageNamed:@"lovebeijing.png"]];
            rqCell.EnglishLabel.text = @"sign in today";
            rqCell.titleLabel.text = @"每日签到";
            rqCell.commentLabel.text = [NSString stringWithFormat:@"%@",artical.comment_count];
            rqCell.backgroundColor = [UIColor clearColor];
            if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isWhite"]) {
                rqCell.EnglishLabel.textColor = [UIColor whiteColor];
                rqCell.titleLabel.textColor = [UIColor whiteColor];
                rqCell.commentLabel.textColor = [UIColor whiteColor];
//                self.nightView = [[UIView alloc]init];
//                self.nightView.backgroundColor = [UIColor blackColor];
//                self.nightView.alpha = 0.5;
//                self.nightView.frame = rqCell.bgImage.bounds;
//                [rqCell.bgImage addSubview:self.nightView];
            }else{
                rqCell.EnglishLabel.textColor = [UIColor blackColor];
                rqCell.titleLabel.textColor = [UIColor blackColor];
                rqCell.commentLabel.textColor = [UIColor blackColor];
//                self.nightView = [[UIView alloc]init];
//                self.nightView.backgroundColor = [UIColor whiteColor];
//                self.nightView.alpha = 0.5;
//                self.nightView.frame = rqCell.bgImage.bounds;
//                [rqCell.bgImage addSubview:self.nightView];
//                self.nightView.hidden = YES;
            }
            return rqCell;
        

        }else
            if ([artical.type_name isEqualToString:@"视频"])
            {
            ArticalVideoTableViewCell *videoCell = [self.tableView dequeueReusableCellWithIdentifier:@"Video"];
            [videoCell.bgImage sd_setImageWithURL:[NSURL URLWithString:[artical.thumb objectForKey:@"raw"]]];
                videoCell.titleLabel.text = artical.title;
                videoCell.describLabel.text = [artical.content objectForKey:@"desc"];
                videoCell.screen_nameLabel.text  = [artical.cp objectForKey:@"screen_name"];
                [videoCell.avatar_largeImage sd_setImageWithURL:[NSURL URLWithString:[artical.cp objectForKey:@"avatar_large"]]placeholderImage:[UIImage imageNamed:@"lovebeijing.png"]];
                videoCell.typeLabel.text = artical.type_name;
                videoCell.backgroundColor = [UIColor clearColor];
                if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isWhite"]) {
                    videoCell.titleLabel.textColor = [UIColor whiteColor];
                    videoCell.describLabel.textColor = [UIColor whiteColor];
                    videoCell.screen_nameLabel.textColor = [UIColor whiteColor];
                    videoCell.typeLabel.textColor = [UIColor whiteColor];
                }else{
                    videoCell.titleLabel.textColor = [UIColor blackColor];
                    videoCell.describLabel.textColor = [UIColor blackColor];
                    videoCell.screen_nameLabel.textColor = [UIColor blackColor];
                    videoCell.typeLabel.textColor = [UIColor blackColor];
                }
            return videoCell;
        }else if (([artical.type_name isEqualToString:@"诗歌"]) || ([artical.type_name isEqualToString:@"段子"])){
            ArticlePicTableViewCell *picCell = [self.tableView dequeueReusableCellWithIdentifier:@"pic"];
            [picCell.bgImage sd_setImageWithURL:[NSURL URLWithString:[artical.thumb objectForKey:@"raw"]]placeholderImage:[UIImage imageNamed:@"lovebeijing.png"]];
            picCell.describLabel.text = [artical.content objectForKey:@"desc"];
//            NSLog(@"%@",picCell.describLabel.text);
            if ([artical.content objectForKey:@"signature"]) {
                picCell.signatureLabel.text = [NSString stringWithFormat:@"--- %@",[artical.content objectForKey:@"signature"]];
                 }
            picCell.screen_nameLabel.text = artical.title;
            picCell.backgroundColor = [UIColor clearColor];
            return picCell;
        }else if ([artical.type_name isEqualToString:@"大型画册"]){
            ActiclePhotoTableViewCell *photoCell = [self.tableView dequeueReusableCellWithIdentifier:@"photo"];
            [photoCell.bgImage sd_setImageWithURL:[NSURL URLWithString:[artical.thumb objectForKey:@"raw"]]placeholderImage:[UIImage imageNamed:@"lovebeijing.png"]];
            photoCell.titleLabel.text = artical.title;
            photoCell.typeLabel.text = artical.type_name;
            [photoCell.avatarImage sd_setImageWithURL:[NSURL URLWithString:[artical.cp objectForKey:@"avatar_large"]]];
            photoCell.screen_nameLabel.text = [artical.cp objectForKey:@"screen_name"];
            photoCell.desc.text = [artical.content objectForKey:@"desc"];
            photoCell.numLabel.text = [NSString stringWithFormat:@"%@",[artical.gallery objectForKey:@"image_count"]];
//            NSLog(@"%@",photoCell.numLabel.text);
//            NSLog(@"%@",[artical.content objectForKey:@"desc"]);
//            NSLog(@"%@",photoCell.desc.text);
            photoCell.backgroundColor = [UIColor clearColor];
            if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isWhite"]) {
                photoCell.titleLabel.textColor = [UIColor whiteColor];
                photoCell.typeLabel.textColor = [UIColor whiteColor];
                photoCell.screen_nameLabel.textColor = [UIColor whiteColor];
                photoCell.desc.textColor = [UIColor whiteColor];
                photoCell.numLabel.textColor = [UIColor whiteColor];
            }else{
                photoCell.titleLabel.textColor = [UIColor blackColor];
                photoCell.typeLabel.textColor = [UIColor blackColor];
                photoCell.screen_nameLabel.textColor = [UIColor blackColor];
                photoCell.desc.textColor = [UIColor blackColor];
                photoCell.numLabel.textColor = [UIColor blackColor];
                
            }
            return photoCell;
        }
        else{

                        ArticleCommonFEIRQTableViewCell *commonCell = [self.tableView dequeueReusableCellWithIdentifier:@"common"];
                        [commonCell.bgimage sd_setImageWithURL:[NSURL URLWithString:[artical.thumb objectForKey:@"raw"]]placeholderImage:[UIImage imageNamed:@"lovebeijing.png"]];
                        commonCell.titleLabel.text = artical.title;
                        commonCell.describLabel.text = [artical.content objectForKey:@"desc"];
                        commonCell.typeNameLabel.text = artical.type_name;
            //            NSLog(@"$$$%@",commonCell.typeNameLabel.text);
                        [commonCell.avatarImage sd_setImageWithURL:[NSURL URLWithString:[artical.cp objectForKey:@"avatar_large"]]placeholderImage:[UIImage imageNamed:@"lovebeijing.png"]];
                        commonCell.screen_nameLabel.text = [artical.cp objectForKey:@"screen_name"];
            //            NSLog(@"%@",[artical.cp objectForKey:@"screen_name"]);
            commonCell.backgroundColor = [UIColor clearColor];
            if (![[NSUserDefaults standardUserDefaults] boolForKey:@"isWhite"]) {
                commonCell.titleLabel.textColor = [UIColor whiteColor];
                commonCell.describLabel.textColor = [UIColor whiteColor];
                commonCell.typeNameLabel.textColor = [UIColor whiteColor];
            }else {
                commonCell.titleLabel.textColor = [UIColor blackColor];
                commonCell.describLabel.textColor = [UIColor blackColor];
                commonCell.typeNameLabel.textColor = [UIColor blackColor];
            }
                            return commonCell;
           
        }
        }
    }
}

- (void)loadDataHandler
{
    NSString *str = [NSString stringWithFormat:@"http://mmmono.com/api/v2/waterfall/?page=2&w_datetime=%@", _nextTime];
//    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//    self.uesTableArr = [NSMutableArray array];
//    self.type_nameArr = [NSMutableArray array];
//    self.specialArr = [NSMutableArray array];
//    self.specialDic = [NSMutableDictionary dictionary];
    [HandleData handleDataWithUrl:str completion:^(id data) {
        NSMutableDictionary *allDic = data;
        //        NSLog(@"WWWWWWW%@",allDic);
        NSDictionary *nextDic = [data objectForKey:@"next"];
        _nextTime = [nextDic objectForKey:@"w_datetime"] ;
        NSMutableArray *arr = [allDic objectForKey:@"waterfall"];
        for (NSMutableDictionary *dic in arr) {
            //            NSLog(@"++++++%@",dic);
            if ( [dic objectForKey:@"item"]) {
                self.useDic = [dic objectForKey:@"item"];
                Artical *artical = [[Artical alloc]init];
                [artical setValuesForKeysWithDictionary:_useDic];
                [self.uesTableArr addObject:artical];
            }else{
                //            self.useDic = [dic objectForKey:@"item"];
                ////            NSLog(@"+++%@",_useDic);
                //
                //            Artical *artical = [[Artical alloc]init];
                //            [artical setValuesForKeysWithDictionary:_useDic];
                //                [self.uesTableArr addObject:artical];
                //            if ([dic objectForKey:@"special"]) {
                self.specialDic = [dic objectForKey:@"special"];
                AticleSpecial *special = [AticleSpecial alloc];
                [special setValuesForKeysWithDictionary:self.specialDic];
                [_uesTableArr addObject:special];
//                NSLog(@"~~~~~~~%@",_uesTableArr);
                //                }
                
            }
            //            NSLog(@"%@",[artical.thumb objectForKey:@"raw"]);
            
        }
        Artical *articaltemp = [self.uesTableArr firstObject];
        NSLog(@"!!!!!!!!!!%@", [articaltemp.thumb objectForKey:@"raw"]);
        
        AticleSpecial *spe = [self.uesTableArr firstObject];
        NSLog(@"_______%@",[spe.thumb objectForKey:@"raw"]);
        
        [self.tableView reloadData];
//        [self.tableView.header endRefreshing];
        
        
    }];

    
}
- (void)passValue:(NSString *)str
{
    MONOViewController *mono = [[MONOViewController alloc]init];
    NSLog(@"$$$$$$%@",str);
    mono.newietm_url = str;
    
    [self.navigationController pushViewController:mono animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
